package io.zhengsh.jmm;

public class SingletonDemo {

    private static volatile SingletonDemo singletonDemo;


    private SingletonDemo() {
        System.out.println(Thread.currentThread().getName() + "\t  invoke SingletonDemo()");
    }

    public static SingletonDemo getSingleton() {
        if (singletonDemo == null) {
            synchronized (SingletonDemo.class) {
                if (singletonDemo == null) {
                    singletonDemo = new SingletonDemo();
                }
            }
        }
        return singletonDemo;
    }
}
